//
// Created by Administrator on 2024/3/17.
//
// O(nlog(n))分治策略
#include<bits/stdc++.h>

using namespace std;//T(n)=T(n/2)*2+O(n)=>T(n)=nlog(n)
int f(vector<int> &v, int left, int right) {
    if (right == left) {
        return v[left];
    }
    int mid = (left + right) / 2;
    int max_left = f(v, left, mid);//
    int max_right = f(v, mid + 1, right);
    int max3_left = INT_MIN, s = 0;
    for (int i = mid; i >= left; i--) {
        s += v[i];
        if (s > max3_left)max3_left = s;

    }
    int max3_right = INT_MIN;
    s = 0;
    for (int i = mid + 1; i <= right; i++) {
        s += v[i];
        if (s > max3_right)max3_right = s;

    }
    return max(max(max_left, max_right), max3_left + max3_right);
}

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (auto &e:v)cin >> e;

    cout << f(v, 0, n - 1) << endl;


    return 0;
}